function vote(form_element,container_id)
{
	var container = "#"+container_id;
	$(container).prepend('<div class="loader"></div>');
	action = 'vote';
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
			$(".loader").remove();
            //get errors from backend
            if(req.responseText)
            {
           		$(container+" .error_text").html();
				$(container+" .error_text").fadeIn('fast');
                $(container+" .error_text").html(req.responseText);
                $(container+" .error_text").fadeOut(5000);
            }
			//get data from backend		
            if (req.responseJS.error == true)
            {
           		$(container+" .error_text").html();
				$(container+" .error_text").fadeIn('fast');
                $(container+" .error_text").html(req.responseJS.error_text);
                $(container+" .error_text").fadeOut(5000);
           	}
           	else
           	{
           		$(container).fadeOut("slow");
           		$(container).html(req.responseJS.output);
           		$(container).fadeIn("slow");
           		$(container+" .error_text").html();
				$(container+" .error_text").fadeIn('fast');
           		$(container+" .error_text").html(req.responseJS.error_text);
				$(container+" .error_text").fadeOut(5000);
           	}
  		}
	}
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/js/ajax/vote.php', true);
	req.send({form:form_element,action:action});
}
$(document).ready(function(){
	$(".vote-submit-button").live('click',function(){
		form = document.getElementById($(this).parent().parent().attr("id"));
		//alert(form.id)
		vote(form,$("#votes").attr("id"));
		return false;
	});
});
